{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Tox 21 dataset exploration\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The purpose of this notebook is as follows,\n",
    "\n",
    " - Explain [Tox21 dataset](https://tripod.nih.gov/tox21/challenge/): Check the labels and visualization of molecules to understand what kind of data are stored.\n",
    " - Explain internal structure of tox21 dataset in `chainer_chemistry`: We handle the dataset with `NumpyTupleDataset`.\n",
    " - Explain how `preprocessor` and `parser` work on `chainer_chemistry`: One concrete example using `NFPPreprocessor` is explained.\n",
    "\n",
    "It is out of scope of this notebook to explain how to train graph convolutional network using this dataset, please refer [document tutorial](http://chainer-chemistry.readthedocs.io/en/latest/tutorial.html#) or try `train_tox21.py` in [tox21 example](https://github.com/pfnet-research/chainer-chemistry/tree/master/examples/tox21) for the model training.\n",
    "\n",
    "[Note]\n",
    "This notebook is executed on 1, March, 2018. \n",
    "The behavior of tox21 dataset in `chainer_chemistry` might change in the future."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Loading modules and set loglevel."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import logging\n",
    "from rdkit import RDLogger\n",
    "from chainer_chemistry import datasets\n",
    "\n",
    "# Disable errors by RDKit occurred in preprocessing Tox21 dataset.\n",
    "lg = RDLogger.logger()\n",
    "lg.setLevel(RDLogger.CRITICAL)\n",
    "\n",
    "# show INFO level log from chainer chemistry\n",
    "logging.basicConfig(level=logging.INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tox 21 dataset consists of train/validation/test data and they can be downloaded automatically with chainer chemistry. \n",
    "The format of tox21 dataset is \"sdf\" file.\n",
    "You can check the file path of downloaded sdf file with `get_tox21_filepath` method. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "train_filepath = datasets.get_tox21_filepath('train')\n",
    "val_filepath = datasets.get_tox21_filepath('val')\n",
    "test_filepath = datasets.get_tox21_filepath('test')\n",
    "\n",
    "print('train_filepath =', train_filepath)\n",
    "print('val_filepath =', val_filepath)\n",
    "print('test_filepath =', test_filepath)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Dataset contains 12 types of toxity, the label of toxity can be checked by `get_tox21_label_names` method.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tox21 label_names = ['NR-AR', 'NR-AR-LBD', 'NR-AhR', 'NR-Aromatase', 'NR-ER', 'NR-ER-LBD', 'NR-PPAR-gamma', 'SR-ARE', 'SR-ATAD5', 'SR-HSE', 'SR-MMP', 'SR-p53']\n"
     ]
    }
   ],
   "source": [
    "label_names = datasets.get_tox21_label_names()\n",
    "print('tox21 label_names =', label_names)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Preprocessing dataset\n",
    "\n",
    "Dataset extraction depends on the preprocessing method, which is determined by `preprocessor`.\n",
    "\n",
    "Here, let's look an example of using `NFPPreprocessor` preprocessor for tox21 dataset exraction.\n",
    "\n",
    "Procedure is as follows,\n",
    "\n",
    "1. Instantiate `preprocessor` (here `NFPPreprocessor` is used).\n",
    "2. call `get_tox21` method with `preprocessor`.\n",
    " - `labels=None` option is used to extract all labels. In this case, 12 types of toxity labels are extracted (see above).\n",
    "\n",
    "[Note] \n",
    " - `return_smiles` option can be used to get SMILES information together with the dataset itself.\n",
    " - Preprocessing result depends on RDKit version. \n",
    "You might get different results due to the difference of RDKit behavior between version."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RDKit version:  2017.03.3\n"
     ]
    }
   ],
   "source": [
    "import rdkit\n",
    "\n",
    "print('RDKit version: ', rdkit.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████| 11764/11764 [00:22<00:00, 531.76it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 11757, TOTAL 11757\n",
      "100%|███████████████████████████████████████████████████████████████████████████████| 296/296 [00:00<00:00, 488.77it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 295, TOTAL 295\n",
      "100%|███████████████████████████████████████████████████████████████████████████████| 647/647 [00:01<00:00, 609.91it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 645, TOTAL 645\n"
     ]
    }
   ],
   "source": [
    "from chainer_chemistry.dataset.preprocessors.nfp_preprocessor import \\\n",
    "    NFPPreprocessor\n",
    "\n",
    "preprocessor = NFPPreprocessor()\n",
    "train, val, test, train_smiles, val_smiles, test_smiles = datasets.get_tox21(preprocessor, labels=None, return_smiles=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Dataset extraction depends on the `preprocessor`, and you may use other type of `preprocessor` as well.\n",
    "\n",
    "Below is another example of using `GGNNPreprocessor` for dataset extraction. But it takes little bit of time, you can skip it for the following tutorial."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████| 11764/11764 [00:29<00:00, 401.74it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 11757, TOTAL 11757\n",
      "100%|███████████████████████████████████████████████████████████████████████████████| 296/296 [00:00<00:00, 336.99it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 295, TOTAL 295\n",
      "100%|███████████████████████████████████████████████████████████████████████████████| 647/647 [00:01<00:00, 479.05it/s]\n",
      "INFO:chainer_chemistry.dataset.parsers.sdf_file_parser:Preprocess finished. FAIL 0, SUCCESS 645, TOTAL 645\n"
     ]
    }
   ],
   "source": [
    "from chainer_chemistry.dataset.preprocessors.ggnn_preprocessor import \\\n",
    "    GGNNPreprocessor\n",
    "\n",
    "# uncomment it if you want to try `GGNNPreprocessor`\n",
    "ggnn_preprocessor = GGNNPreprocessor()\n",
    "results = datasets.get_tox21(ggnn_preprocessor, labels=None, return_smiles=True)\n",
    "train_ggnn, val_ggnn, test_ggnn, train_smiles_ggnn, val_smiles_ggnn, test_smiles_ggnn = results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Check extracted dataset\n",
    "\n",
    "First, let's check number of data for train/validation/test dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dataset information...\n",
      "train <class 'chainer_chemistry.datasets.numpy_tuple_dataset.NumpyTupleDataset'> 11757\n",
      "val <class 'chainer_chemistry.datasets.numpy_tuple_dataset.NumpyTupleDataset'> 295\n",
      "test <class 'chainer_chemistry.datasets.numpy_tuple_dataset.NumpyTupleDataset'> 645\n",
      "smiles information...\n",
      "train_smiles <class 'numpy.ndarray'> 11757\n"
     ]
    }
   ],
   "source": [
    "print('dataset information...')\n",
    "print('train', type(train), len(train))\n",
    "print('val', type(val), len(val))\n",
    "print('test', type(test), len(test))\n",
    "\n",
    "print('smiles information...')\n",
    "print('train_smiles', type(train_smiles), len(train_smiles))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are 11757 data in `train`, 295 data in `val` and 645 data in `test` respectively.\n",
    "(You might get different result with different version of `rdkit`.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The dataset is a class of `NumpyTupleDataset`, where i-th dataset features can be accessed by `dataset[i]`.\n",
    "\n",
    "When `NFPPreprocessor` is used, each dataset consists of following features\n",
    " 1. atom feature: representing atomic number of given molecule. \n",
    " 2. adjacency matrix feature: representing adjacency matrix of given molecule.\n",
    " 3. label feature: representing toxity (label) of given molecule.\n",
    "    Here, 0 indicates negative (no toxity), 1 indicates positive (toxic) and -1 indicates data is not available, respectively."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's look an example of 6-th train dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index=6, SMILES=Cc1ccc([N+](=O)[O-])c2c1O[Hg]2\n",
      "atom (12,) [ 6  6  6  6  6  7  8  8  6  6  8 80]\n",
      "adj (12, 12)\n",
      "[[1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
      " [1. 1. 1. 0. 0. 0. 0. 0. 0. 1. 0. 0.]\n",
      " [0. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
      " [0. 0. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 1. 1. 1. 0. 0. 1. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 1. 1. 1. 1. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0. 1. 1. 0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 1. 0. 0. 0. 1. 1. 0. 1.]\n",
      " [0. 1. 0. 0. 0. 0. 0. 0. 1. 1. 1. 0.]\n",
      " [0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 1. 1.]\n",
      " [0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 1. 1.]]\n",
      "labels [-1 -1 -1 -1 -1 -1 -1 -1 -1  1 -1 -1]\n"
     ]
    }
   ],
   "source": [
    "index = 6\n",
    "\n",
    "print('index={}, SMILES={}'.format(index, train_smiles[index]))\n",
    "atom, adj, labels = train[index]\n",
    "# This molecule has N=12 atoms.\n",
    "print('atom', atom.shape, atom)\n",
    "# adjacency matrix is NxN matrix, where N is number of atoms in the molecule.\n",
    "# Unlike usual adjacency matrix, diagonal elements are filled with 1, for NFP calculation purpose.\n",
    "print('adj', adj.shape)\n",
    "print(adj)\n",
    "print('labels', labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Visualizing the molecule\n",
    "\n",
    "One might want to visualize molecule given SMILES information.\n",
    "Here is an example code:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# This script is referred from http://rdkit.blogspot.jp/2015/02/new-drawing-code.html\n",
    "# and http://cheminformist.itmol.com/TEST/wp-content/uploads/2015/07/rdkit_moldraw2d_2.html\n",
    "from __future__ import print_function\n",
    "from rdkit import Chem\n",
    "from rdkit.Chem.Draw import IPythonConsole\n",
    "from IPython.display import SVG\n",
    "\n",
    "from rdkit.Chem import rdDepictor\n",
    "from rdkit.Chem.Draw import rdMolDraw2D\n",
    "def moltosvg(mol,molSize=(450,150),kekulize=True):\n",
    "    mc = Chem.Mol(mol.ToBinary())\n",
    "    if kekulize:\n",
    "        try:\n",
    "            Chem.Kekulize(mc)\n",
    "        except:\n",
    "            mc = Chem.Mol(mol.ToBinary())\n",
    "    if not mc.GetNumConformers():\n",
    "        rdDepictor.Compute2DCoords(mc)\n",
    "    drawer = rdMolDraw2D.MolDraw2DSVG(molSize[0],molSize[1])\n",
    "    drawer.DrawMolecule(mc)\n",
    "    drawer.FinishDrawing()\n",
    "    svg = drawer.GetDrawingText()\n",
    "    return svg\n",
    "\n",
    "def render_svg(svg):\n",
    "    # It seems that the svg renderer used doesn't quite hit the spec.\n",
    "    # Here are some fixes to make it work in the notebook, although I think\n",
    "    # the underlying issue needs to be resolved at the generation step\n",
    "    return SVG(svg.replace('svg:',''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "smiles: Cc1ccc([N+](=O)[O-])c2c1O[Hg]2\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg baseProfile=\"full\" height=\"150px\" version=\"1.1\" width=\"450px\" xml:space=\"preserve\" xmlns:rdkit=\"http://www.rdkit.org/xml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<rect height=\"150\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"450\" x=\"0\" y=\"0\"> </rect>\n",
       "<path d=\"M 110.606,38.6588 158.225,44.9246\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 158.225,44.9246 187.461,6.81818\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 170.231,45.0558 190.697,18.3813\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 158.225,44.9246 176.608,89.2969\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 187.461,6.81818 235.08,13.084\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 235.08,13.084 253.463,57.4563\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 228.963,23.4165 241.831,54.4771\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 253.463,57.4563 272.4,59.9481\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 272.4,59.9481 291.338,62.4399\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 253.463,57.4563 224.227,95.5627\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 300.293,74.3658 306.002,88.1468\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 306.002,88.1468 311.712,101.928\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 309.167,70.6892 314.877,84.4702\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 314.877,84.4702 320.586,98.2511\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 307.838,54.9167 315.7,44.6689\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 315.7,44.6689 323.562,34.4211\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 224.227,95.5627 176.608,89.2969\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 218.337,85.099 185.004,80.7129\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 224.227,95.5627 219.014,135.177\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 176.608,89.2969 174.002,109.104\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 174.002,109.104 171.395,128.911\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 177.818,137.9 191.749,139.733\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 191.749,139.733 205.68,141.566\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<text style=\"font-size:16px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"291.338\" y=\"72.5275\"><tspan>N</tspan><tspan style=\"baseline-shift:super;font-size:12px;\">+</tspan><tspan/></text>\n",
       "<text style=\"font-size:16px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"311.989\" y=\"116.099\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:16px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"321.242\" y=\"34.4211\"><tspan>O</tspan><tspan style=\"baseline-shift:super;font-size:12px;\">-</tspan><tspan/></text>\n",
       "<text style=\"font-size:16px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"162.866\" y=\"144.921\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:16px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#000000\" x=\"205.68\" y=\"151.187\"><tspan>Hg</tspan></text>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "smiles = train_smiles[index]\n",
    "mol = Chem.MolFromSmiles(train_smiles[index])\n",
    "\n",
    "print('smiles:', smiles)\n",
    "render_svg(moltosvg(mol))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Note] SVG images cannot be displayed on GitHub, but you can see an image of molecule when you execute it on jupyter notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Interactively watch through the tox21 dataset\n",
    "\n",
    "Jupyter notebook provides handy module to check/visualize the data.\n",
    "Here `interact` module can be used to interactively check the internal of tox 21 dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index=5878, SMILES=CN(C)CCn1nnnc1SCC1=C(C(=O)O)N2C(=O)C(NC(=O)Cc3csc(N)n3)C2SC1.Cl\n",
      "atom [ 6  7  6  6  6  7  7  7  7  6 16  6  6  6  6  8  8  7  6  8  6  7  6  8\n",
      "  6  6  6 16  6  7  7  6 16  6 17]\n",
      "labels [ 0  0  0  0  0  0  0 -1  0 -1  0  0]\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg baseProfile=\"full\" height=\"150px\" version=\"1.1\" width=\"450px\" xml:space=\"preserve\" xmlns:rdkit=\"http://www.rdkit.org/xml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<rect height=\"150\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"450\" x=\"0\" y=\"0\"> </rect>\n",
       "<path d=\"M 63.4663,27.5705 72.4585,31.2406\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 72.4585,31.2406 81.4507,34.9107\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 88.1003,33.689 95.5312,27.9255\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 95.5312,27.9255 102.962,22.162\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 85.3008,40.1037 86.5994,49.5872\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 86.5994,49.5872 87.8981,59.0706\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 87.8981,59.0706 109.207,67.7678\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 109.207,67.7678 110.506,77.2513\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 110.506,77.2513 111.805,86.7348\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 109.005,93.7589 99.0422,103.312\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 115.655,92.3537 124.134,96.9007\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 124.134,96.9007 132.613,101.448\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 97.5715,110.336 103.879,123.386\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 102.662,110.29 107.078,119.425\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 109.058,126.767 125.212,124.555\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 129.227,120.264 130.92,110.856\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 130.92,110.856 132.613,101.448\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 125.205,116.626 126.39,110.04\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 126.39,110.04 127.575,103.455\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 132.613,101.448 141.438,97.1819\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 141.438,97.1819 150.264,92.9162\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 156.407,93.5191 164.389,98.9441\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 164.389,98.9441 172.37,104.369\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 172.37,104.369 193.092,94.3528\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 193.092,94.3528 212.128,107.29\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 198.535,92.4864 211.86,101.543\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 193.092,94.3528 194.779,71.399\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 212.128,107.29 210.441,130.244\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 212.128,107.29 220.826,103.086\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 220.826,103.086 229.525,98.8812\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 209.147,132.148 216.874,137.399\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 216.874,137.399 224.6,142.65\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 211.735,128.341 219.461,133.592\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 219.461,133.592 227.187,138.843\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 210.441,130.244 203.534,133.583\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 203.534,133.583 196.627,136.922\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 236.174,97.5184 245.989,98.2396\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 245.989,98.2396 255.804,98.9607\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 233.132,93.4382 233.834,83.8792\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 233.834,83.8792 234.536,74.3203\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 254.061,100.465 259.925,107.258\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 259.925,107.258 265.789,114.052\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 257.546,97.4569 263.41,104.251\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 263.41,104.251 269.273,111.044\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 255.804,98.9607 257.49,76.0069\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 257.49,76.0069 263.98,70.4058\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 263.98,70.4058 270.469,64.8047\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 257.49,76.0069 234.536,74.3203\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 281.563,63.2847 289.106,65.9117\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 289.106,65.9117 296.649,68.5387\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 294.388,68.9699 296.178,78.3561\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 296.178,78.3561 297.968,87.7422\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 298.91,68.1076 300.7,77.4937\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 300.7,77.4937 302.49,86.8799\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 296.649,68.5387 314.072,53.5005\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 314.072,53.5005 335.807,61.0706\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 335.807,61.0706 354.707,47.936\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 341.269,62.8804 354.499,53.6862\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 335.807,61.0706 338.554,70.1695\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 338.554,70.1695 341.301,79.2683\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 354.707,47.936 362.338,53.7283\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 362.338,53.7283 369.968,59.5205\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 371.703,65.6881 368.586,74.6377\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 368.586,74.6377 365.469,83.5873\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 365.469,83.5873 370.57,90.9275\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 370.57,90.9275 375.672,98.2677\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 365.469,83.5873 355.626,83.3807\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 355.626,83.3807 345.784,83.1741\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 362.613,78.9232 355.723,78.7786\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 355.723,78.7786 348.833,78.6339\" style=\"fill:none;fill-rule:evenodd;stroke:#0000FF;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 234.536,74.3203 226.554,68.8953\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 226.554,68.8953 218.573,63.4703\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 212.429,62.8674 203.604,67.1332\" style=\"fill:none;fill-rule:evenodd;stroke:#CCCC00;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 203.604,67.1332 194.779,71.399\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"81.4507\" y=\"40.1037\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"109.005\" y=\"94.4067\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"92.3926\" y=\"110.336\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"102.409\" y=\"131.058\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"125.212\" y=\"127.936\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#CCCC00\" x=\"150.264\" y=\"95.2674\"><tspan>S</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"225.894\" y=\"147.018\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"182.812\" y=\"144.096\"><tspan>HO</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"229.525\" y=\"101.11\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"267.259\" y=\"120.22\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"268.264\" y=\"64.8047\"><tspan>NH</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"297.378\" y=\"94.9829\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#CCCC00\" x=\"369.968\" y=\"65.6881\"><tspan>S</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"370.674\" y=\"106.707\"><tspan>NH</tspan><tspan style=\"baseline-shift:sub;font-size:5.25px;\">2</tspan><tspan/></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#0000FF\" x=\"339.134\" y=\"86.9402\"><tspan>N</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#CCCC00\" x=\"212.429\" y=\"65.2186\"><tspan>S</tspan></text>\n",
       "<text style=\"font-size:7px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#00CC00\" x=\"209.454\" y=\"10.6541\"><tspan>ClH</tspan></text>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.show_train_dataset>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from ipywidgets import interact\n",
    "\n",
    "def show_train_dataset(index):\n",
    "    atom, adj, labels = train[index]\n",
    "    smiles = train_smiles[index]\n",
    "    print('index={}, SMILES={}'.format(index, smiles))\n",
    "    print('atom', atom)\n",
    "    # print('adj', adj)\n",
    "    print('labels', labels)\n",
    "    mol = Chem.MolFromSmiles(train_smiles[index])\n",
    "    return render_svg(moltosvg(mol))\n",
    "\n",
    "interact(show_train_dataset, index=(0, len(train) - 1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Appendix: how to save the molecule figure?\n",
    "\n",
    "### 1. Save with SVG format\n",
    "\n",
    "First method is simply save svg in file.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "dirpath = 'images'\n",
    "\n",
    "if not os.path.exists(dirpath):\n",
    "    os.mkdir(dirpath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def save_svg(mol, filepath):\n",
    "    svg = moltosvg(mol)\n",
    "    with open(filepath, \"w\") as fw:\n",
    "        fw.write(svg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "drawing images\\mol_6.svg\n"
     ]
    }
   ],
   "source": [
    "index = 6\n",
    "save_filepath = os.path.join(dirpath, 'mol_{}.svg'.format(index))\n",
    "print('drawing {}'.format(save_filepath))\n",
    "\n",
    "mol = Chem.MolFromSmiles(train_smiles[index])\n",
    "save_svg(mol, save_filepath)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Save with png format\n",
    "\n",
    "`rdkit` provides `Draw.MolToFile` method to visualize mol instance and save it to png format."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from rdkit.Chem import Draw\n",
    "\n",
    "def save_png(mol, filepath, size=(600, 600)):\n",
    "    Draw.MolToFile(mol, filepath, size=size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "drawing images\\mol_6.png\n"
     ]
    }
   ],
   "source": [
    "index = 6\n",
    "save_filepath = os.path.join(dirpath, 'mol_{}.png'.format(index))\n",
    "print('drawing {}'.format(save_filepath))\n",
    "\n",
    "mol = Chem.MolFromSmiles(train_smiles[index])\n",
    "save_png(mol, save_filepath, size=(600, 600))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
